import requests from '../config/request.js'
const qiniuUrl = 'http://qiniu.whle.cn/'

export const getHomeInfo = (payload) => {
    return requests.httpTokenRequest({
        url: "/User/Login",
        data:payload
    });
};


export const getDefaultInfo = (payload) => {
    return requests.httpRequest({
        url: "/Home/GetDefaultInfo",
        data:payload
    });
};

export const getRoomImg = (payload) => {
    return requests.httpRequest({
        url: "/Home/GetRoomImg",
        data:payload
    });
};

export const checkAccountPayOrder = (payload) => {
    return requests.httpTokenRequest({
        url: "/Home/CheckAccountPayOrder",
        data:payload
    });
};

export const getConsumptionTypeList = (payload) => {
    return requests.httpTokenRequest({
        url: "/APP/GetConsumptionTypeList",
        data:payload
    });
};

export const getRefundStatusList = (payload) => {
    return requests.httpTokenRequest({
        url: "/APP/GetRefundStatusList",
        data:payload
    });
};

//审核版本
export const getAuditHomeIcon = (payload) => {
    return requests.httpRequest({
        url: "/Home/GetAuditHomeIcon",
        data:payload
    });
};

//生产环境
export const getRunHomeIcon = (payload) => {
    return requests.httpRequest({
        url: "/Home/GetRunHomeIcon",
        data:payload
    });
};

const getQiNiuToken = (payload) => {
    return requests.httpTokenRequest({
        url: "/Login/GetQiNiuToken",
        data:payload
    });
};

//上传图片到七牛
export const uploadImageToQiNiu = (num,file_type, callback) => {
	uni.chooseImage({
		count: num,
		success: (res) => {
			uni.showLoading({
				title: '上传中...'
			});
			let tempFilePaths = res.tempFilePaths
			getQiNiuToken({fileType:file_type,fileName: tempFilePaths[0]}).then(function(result){
				for (var i = 0; i < tempFilePaths.length; i++) {
					uni.uploadFile({
						url: "https://up.qiniup.com",//华东地区用这个
						filePath: tempFilePaths[i],
						name: 'file',
						formData: {
							'key': result.filePath,
							'token': result.token
						},
						success: (uploadFileRes) => {
							callback(qiniuUrl+JSON.parse(uploadFileRes.data).key);
						},
						fail: (error) => {
							if (error && error.response) {
								uni.showToast({
									title:error.response,
									icon:null
								})
							}
						},
						complete: () => {
							setTimeout(function() {
								uni.hideLoading();
							}, 250);
						},
					});
				}
			});
		}
	});
}

//上传视频到七牛
export const uploadVideoToQiNiu = (file_type,callback) => {
	uni.chooseVideo({
		maxDuration:60,
		sourceType:['album'],
		success: (res) => {
			uni.showLoading({
				title: '上传中...'
			});
			let tempFilePath = res.tempFilePath
			getQiNiuToken({fileType:file_type,fileName: tempFilePath}).then(function(result){
				uni.uploadFile({
					url: "http://upload.qiniu.com/",//华东地区用这个
					filePath: tempFilePath,
					name: 'file',
					formData: {
						'key': result.filePath,
						'token': result.token
					},
					success: (uploadFileRes) => {
						callback(qiniuUrl+JSON.parse(uploadFileRes.data).key);
					},
					fail: (error) => {
						if (error && error.response) {
							uni.showToast({
								title:error.response,
								icon:null
							})
						}
					},
					complete: () => {
						setTimeout(function() {
							uni.hideLoading();
						}, 250);
					},
				});
			});
		}
	});
}


// ******************************************新接口
// 教練接口
export const queryPlayerList = (payload) => {
    return requests.httpRequest({
        url: "/client/serverPlayer/queryPlayerList",
        data:payload
    });
};
// 商品
export const listMallProduct = (payload) => {
    return requests.httpRequest({
        url: "/client/mallProduct/listMallProduct",
        data:payload
    });
};

// 商品
export const allHomePage = (payload) => {
    return requests.httpRequest({
        url: "/client/homePage/allHomePage?homePageImageType="+payload.homePageImageType,
        data:payload
    });
};

